<?php
use yii\helpers\Html;
use yii\widgets\LinkPager;
use yii\helpers\Url;
?>
<style>
    .form-inline{width: auto;word-spacing: -6px;/*color: #e5e5e5;*/}
    .form-inline input[type="text"]{height: 40px;line-height: 40px;vertical-align: middle;}
    .btnMd{width: 100px; color: #fff;border-radius: 6px; height: 40px;line-height: 40px;vertical-align: middle;}
    .btnMd input[type="submit"]{display: block; width: 100%; background: 0;border:0;font-size: 17px;vertical-align: middle}
    @media (max-width: 1440px){
        .form-inline input[type="text"]{width: 98px;}
    }
</style>
 <div class="row borB">
    <div class="container lh30">
			<span class="z">
                <?= isset($this->params['crumbs']) ? $this->params['crumbs'] : '' ?>
			</span>
			<span class="y">
				<a href="#"></a>
			</span>
    </div>
    <div class="right_site right_52">
			<span class="z">
				<form name="form" action=""  method="post" >
                    <input type="hidden" name="" value="" id="upload_id" />
                    <input type="submit" style="display:none;" id="upload_sub" />
                </form>

			</span>
    </div>
</div>

    <div class="container">
        <div class="clearfix mg20-y">

            <a href="<?=Url::toRoute('add') ?>" class="add_upload btnBg">新增代理商</a>
            
            <div style="display: inline-block;">
                <form class="form-inline" action="">
                    <div class="form-group">
                        <label class="mg20-x" for="">账户名</label>
                        <input type="text" name="login_name">
                    </div>

                    <div class="form-group">
                        <label class="mg20-x" for="">代理商</label>
                        <input type="text" name="user_name">
                    </div>

                    <div class="form-group">
                        <label class="mg20-x" for="">负责人</label>
                        <input type="text" name="director">
                    </div>

                    <div class="form-group mr20">
                        <label class="mg20-x" for="">电话</label>
                        <input type="text" name="mobile">
                    </div>

                    <div class="form-group">
                        <div class="btnMd">
                            <input type="submit" value="搜索">
                        </div>

                    </div>
                </form>
            </div>
        </div>

            <table class="table table-bordered">
                <thead>
                <tr>
                    <th style="text-align:center">日期</th>
                    <th style="text-align:center">账户名称</th>
                    <th style="text-align:center">用户密码</th>
                    <th style="text-align:center">代理商名称</th>
                    <th style="text-align:center">负责人</th>
                    <th style="text-align:center">联系电话</th>
                    <th style="text-align:center">授权点数</th>
                    <th style="text-align:center">操作</th>
                </tr>
                </thead>
                 <tbody>
                    <?php foreach ($list as $val) {?>
                        <tr>
                            <td class="center"><?= $val['create_time'] ?></td>
                            <td class="center"><?= Html::encode($val['login_name']) ?></td>
                            <td class="center"></td>
                            <td class="center"><?= $val['user_name'] ?></td>
                            <td class="center"><?= $val['director'] ?></td>
                            <td class="center"><?= $val['mobile'] ?></td>
                            <td class="center"><?= $val['point'] ?></td>
                            <td class="center">
                                <a href="<?= Url::to(['edit', 'id' => $val['uid']]) ?>" class="edit btn btn-sm btn-edit">修改</a><input type="submit" style="display:none;" />
                                <?php if ($val['status'] == 1) { ?>
                                    <a href="javascript:void();" onclick="editStatus(<?= $val['uid'] ?>, 0)" class="edit btn btn-sm btn-del">停用</a><input type="submit" style="display:none;" />
                                <?php } else { ?>
                                    <a href="javascript:void();" onclick="editStatus(<?= $val['uid'] ?>, 1)" class="edit btn btn-sm btn-edit">启用</a><input type="submit" style="display:none;" />
                                <?php } ?>
                                <a href="javascript:void();" onclick="editStatus(<?= $val['uid'] ?>, -1)" class="edit btn btn-sm btn-end">删除</a><input type="submit" style="display:none;" />
                            </td>
                        </tr>
                    <?php }?>
                 </tbody>
            </table>
            <div class="page">
                <?=LinkPager::widget([
                    'pagination' => $page,
                    'firstPageLabel' => '首页',
                    'nextPageLabel' => '下一页',
                    'prevPageLabel' => '上一页',
                    'lastPageLabel' => '末页',
                ]); ?>
            </div>
    </div>

<?php $this->beginBlock('js_index') ?>

/**
 * 修改代理商状态
 * @param id 代理商id
 */
function editStatus(id, status) {
    $.get("<?= Url::to(['editstatus']) ?>", {id:id, status:status},
    function(status) {
        location.reload();
    });
}

<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['js_index'], $this::POS_END); ?>
